package com.mofang.controller;

import java.util.ArrayList;

import com.mofang.model.RecommendationModel;
import com.pactera.framework.controller.BaseController;
import com.pactera.framework.exception.IException;
import com.pactera.framework.model.MapEntity;

public class RecommendationController extends BaseController {

	/** 获取我的推荐记录 */
	private static final int Get_recommendations_key = 0;
	/** 提交推荐 */
	private static final int Add_recommendation_key = 1;

	public void getRecommendations(
			final UpdateViewAsyncCallback<ArrayList<MapEntity>> viewUpdateCallback,
			final String userId) {
		doAsyncTask(Get_recommendations_key, viewUpdateCallback,
				new DoAsyncTaskCallback<String, ArrayList<MapEntity>>() {
					@Override
					public ArrayList<MapEntity> doAsyncTask(String... params)
							throws IException {
						// throw new ServerException();
						final RecommendationModel model = new RecommendationModel();
						return model.getRecommendationList(params[0]);
					}
				}, userId);

	}

	public void addClerk(
			final UpdateViewAsyncCallback<String> viewUpdateCallback,
			final MapEntity clerkEntity) {
		doAsyncTask(Add_recommendation_key, viewUpdateCallback,
				new DoAsyncTaskCallback<MapEntity, String>() {
					@Override
					public String doAsyncTask(MapEntity... arg0)
							throws IException {
						final RecommendationModel model = new RecommendationModel();
						return model.addRecommend(arg0[0]);
					}
				}, clerkEntity);

	}

	public void cancelGetRecommendations() {
		cancel(Get_recommendations_key);
	}

	public void cancelAddClerk() {
		cancel(Add_recommendation_key);
	}

}
